using micromsg;
using MicroMsg.Common.Algorithm;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Scene;
using System;
using System.Collections.Generic;
namespace MicroMsg.Plugin.Sns.Scene
{
	public class NetSceneSnsObjectOp : NetSceneBaseEx<SnsObjectOpRequest, SnsObjectOpResponse, SnsObjectOpRequest.Builder>
	{
		private const string TAG = "NetSceneSnsObjectOp";
		private NetSceneSnsObjectOpCallBack onOpRsp;
		private static SKBuiltinBuffer_t emptyCommentID = Util.toSKBuffer("");
		public NetSceneSnsObjectOp()
		{
		}
		public NetSceneSnsObjectOp(NetSceneSnsObjectOpCallBack netSceneSnsObjectOpCallBack_0)
		{
			this.onOpRsp = netSceneSnsObjectOpCallBack_0;
		}
		public bool doScene(List<SnsOpLog> opList)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			using (List<SnsOpLog>.Enumerator enumerator = opList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					SnsOpLog current = enumerator.get_Current();
					SnsObjectOp.Builder builder = SnsObjectOp.CreateBuilder();
					builder.Id = current.nObjectID;
					builder.OpType = (uint)current.nOpType;
					builder.Ext = ((current.nDelCommentId == 0) ? NetSceneSnsObjectOp.emptyCommentID : Util.toSKBuffer(SnsObjectOpDeleteComment.CreateBuilder().SetCommentId(current.nDelCommentId).Build().ToByteArray()));
					this.mBuilder.OpListList.Add(builder.Build());
				}
			}
			this.mBuilder.OpCount = (uint)this.mBuilder.OpListList.get_Count();
			this.mSessionPack.mCmdID = 104;
			return base.endBuilder();
		}
		protected override void onFailed(SnsObjectOpRequest request, SnsObjectOpResponse response)
		{
			Log.smethod_1("NetSceneSnsObjectOp", "send request failed");
			if (this.onOpRsp != null)
			{
				this.onOpRsp(null);
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_OPLOG_ERR, request.OpListList.get_Item(0).OpType, null);
		}
		protected override void onSuccess(SnsObjectOpRequest request, SnsObjectOpResponse response)
		{
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret != RetConst.MM_OK)
			{
				Log.smethod_1("NetSceneSnsObjectOp", "send request failed ret =" + ret);
				if (this.onOpRsp != null)
				{
					this.onOpRsp(null);
				}
				EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_OPLOG_ERR, request.OpListList.get_Item(0).OpType, null);
				return;
			}
			if (this.onOpRsp != null)
			{
				this.onOpRsp(response.OpRetListList);
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_OPLOG_SUCCESS, request.OpListList.get_Item(0).OpType, null);
		}
		public static string createOpID()
		{
			return MD5Core.GetHashString(AccountMgr.getCurAccount().strUsrName + Util.getNowMilliseconds());
		}
	}
}
